package com.meichis.yndms.vm;

import androidx.lifecycle.MutableLiveData;

import com.amap.api.location.AMapLocation;
import com.meichis.mcsappframework.utils.MessageTools;
import com.meichis.mcsappframework.utils.SharePreferenceUtil;
import com.meichis.yndms.model.ClientInfo;
import com.meichis.yndms.model.DicDataItem;
import com.meichis.yndms.model.UserInfo;
import com.meichis.yndms.repository.manager.ClientNearListManager;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xmy
 * @title
 * @remake
 * @create 2021-04-14 22:51
 */
public class ClientNearListVM extends MyViewModel {
    private MutableLiveData<List<ClientInfo>> clientInfoList;
    private MutableLiveData<String> FindKey;
    private AMapLocation location = null;
    private int MaxDistance = 1000;
    public int PageIndex;
    public boolean isLoading = true;
    private List<DicDataItem> distanceList = null;
    private MutableLiveData<UserInfo> userInfo;

    public void setMaxDistance(int maxDistance) {
        MaxDistance = maxDistance;
    }

    public AMapLocation getLocation() {
        return location;
    }

    public void setLocation(AMapLocation location) {
        this.location = location;
    }

    public List<DicDataItem> getDistanceList() {
        if (distanceList == null) {
            distanceList = new ArrayList<>();
            distanceList.add(new DicDataItem(0, "全部"));
            distanceList.add(new DicDataItem(200, "200米"));
            distanceList.add(new DicDataItem(500, "500米"));
            distanceList.add(new DicDataItem(1000, "1公里"));
            distanceList.add(new DicDataItem(5000, "5公里"));
            distanceList.add(new DicDataItem(10000, "10公里"));
        }
        return distanceList;
    }

    public MutableLiveData<String> getFindKey() {
        if (FindKey == null) {
            FindKey = new MutableLiveData<>();
            FindKey.setValue("");
        }
        return FindKey;
    }

    public MutableLiveData<List<ClientInfo>> getClientInfoList() {
        if (clientInfoList == null) {
            clientInfoList = new MutableLiveData<>();
        }
        return clientInfoList;
    }


    public void GetNearRetailerList() {
        if (getLocation() != null) {
            ClientNearListManager.getInstance().GetNearRetailerList(getShowDialog(), getUserInfo().getValue().getOrgId(),
                    getUserInfo().getValue().getId(), getFindKey().getValue(), getLocation().getLatitude(),
                    getLocation().getLongitude(), MaxDistance, PageIndex, 20, getClientInfoList());
            PageIndex++;
        } else {
            MessageTools.showLongToast("请稍后，正在定位！");
        }

    }
}
